<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Models\LogCache;
class CacheController extends CommonController
{
    /**
     * 获取缓存列表
     */
    public function getList()
    {
        $lists = LogCache::orderBy('id','asc')->paginate(10);
        return view('logcache.list',array('actions'=>$this->actions,'lists'=>$lists));
    }
    public function search(Request $request)
    {
        $data  = $request->input();
        $sql = LogCache::orderBy('id','asc');
        if(isset($data['name']) && $data['name'] !='')
        {
            $sql -> where('name','like','%'.trim($data['name'].'%'));
        }
        if(isset($data['action']) && $data['action'] !='')
        {
            $sql -> where('action','like','%'.trim($data['action'].'%'));
        }
        $lists = $sql->paginate(10);
        return view('logcache.search')->with('lists',$lists)->with("lists", $lists)->with("name", $data['name'])
            ->with("action", $data['action'])->with("actions", $this->actions);
    }
    public function postDel(Request $request)
    {
        $data = $request->input();
        $action = $data['action'];
        $url = $this->wjtrUrl."script/cache/".$action;
        $result = @curl($url,array());
        if($result == 1 || $result == '')
        {
            return AjaxCallbackMessage('缓存删除成功', true);
        }else{
            return AjaxCallbackMessage('缓存清除失败', false);
        }
    }
}
